home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1991 / number4 / vidinfo.cpp < prev    next >
Text File  |  1991-08-12  |  2KB  |  97 lines

  1. #pragma option -k-  // Disable stack from if not needed
  2. #pragma option -O   // Eliminate redundant jumps(to self etc...)
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <dos.h>
  7. #include <conio.h>
  8. #include <string.h>
  9.  
  10. #define ERROR -1
  11. typedef unsigned int uint;
  12. typedef unsigned char uchar;
  13.  
  14. int         redirected();
  15. uint         get_key();
  16. char         *dump(uint offset,uint segment);
  17. void         next_page();
  18.  
  19. main()
  20. {
  21.     int redirection = redirected(), i, j;
  22.     if(!redirection) clrscr();
  23.     printf("╔════════════════════════════════════════════╗\n");
  24.     printf("║ Video Information      Bios Dump C000-C0FF ║\n");
  25.     printf("╠════════════════════════════════════════════╣\n");
  26.     for(i = j = 0;i < 20;i++,j += 8)
  27.         printf("║ %s ║\n",dump(0xc000,uint(j)));
  28.     if(!redirection) next_page();
  29.     for(;j < 256;j += 8)
  30.         printf("║ %s ║\n",dump(0xc000,uint(j)));
  31.     printf("╚════════════════════════════════════════════╝\n");
  32.     if(!redirection) {
  33.         printf(" Press any key to continue... ");
  34.         get_key(); clrscr();
  35.     }
  36. }
  37.  
  38. void next_page()
  39. {
  40.     printf("╚════════════════════════════════════════════╝\n");
  41.     printf(" Press any key to continue... ");
  42.     get_key(); clrscr();
  43.     printf("╔════════════════════════════════════════════╗\n");
  44. }
  45.  
  46. char *dump(uint offset,uint segment)
  47. {
  48.     int   i;
  49.     uchar far *ptr = (uchar far *)MK_FP(offset,segment);
  50.     static char string[80];
  51.     uchar   c;
  52.     char    trailer[40], temp[40];
  53.  
  54.     sprintf(string,"%04X:%04X ",offset,segment);
  55.     trailer[0] = temp[0] = 0;
  56.     for(i = 0;i < 8;i++) {
  57.         c = *ptr++;
  58.         sprintf(temp,"%02x ",c);
  59.         strcat(string,temp);
  60.         if(c < ' ' || c > 126) temp[0] = '.';
  61.         else                   temp[0] = c;
  62.         temp[1] = 0;
  63.         strcat(trailer,temp);
  64.     }
  65.     strcat(string,trailer);
  66.     return string;
  67. }
  68.  
  69. uint get_key()
  70. {
  71.     asm {
  72.         xor    ah,ah
  73.         int    0x16
  74.     }
  75.     return _AX;
  76. }
  77.  
  78. int redirected()
  79. {
  80.    asm {
  81.      push    ds
  82.      mov    ax,_psp         // Get segment of PSP
  83.      mov    ds,ax           // Put it in DS
  84.      xor    bx,bx           // Zero out BX
  85.      les     bx,[bx + 0x34]  // Move table adr. at DS:BX to ES & BX
  86.      mov     al,es:[bx]    // stdin normally = 1(i.e. CON)
  87.      mov    ah,es:[bx + 1]    // stdout normally = 1(i.e. CON)
  88.      pop    ds
  89.      cmp    al,ah           // Compare the two handles
  90.      mov    ax,1            // Return 1 if not equal
  91.      jne    EXIT
  92.      xor    ax,ax           // Clear to 0 AX if equal
  93.    }
  94. EXIT:
  95.     return _AX;
  96. }
  97.